
-- =============================================================================
-- SOUND: https://freesound.org/people/yaplasut1843/sounds/523307/
-- =============================================================================
local getInitialName = function(mobName)
	local isShowed = minetest.settings:get_bool("simpleanimals.initial_nametags")
	if isShowed then
		return mobName
	end
end

mobs:register_mob("birdie:birdie", {
	nametag = getInitialName("BIRD"),
	type = "animal",
	passive = true,
	pathfinding = true,
	-- reach = 0,
	-- damage = 0,
	hp_min = 8,
	hp_max = 8,
	armor = 100,
	collisionbox = {-0.3, -0.5, -0.3, 0.3, 0.1, 0.3},
	visual = "mesh",
	mesh = "bird.b3d",
	rotate = 180,
	textures = {
		{"bird_yellow.png"},
		{"bird_blue.png"},
		{"bird_brown.png"},
		{"bird_red.png"},
		{"bird_green.png"},
		{"bird_pink.png"}
	},
	--blood_texture = "",
	sounds = {
		random = "birdie",
		--death = "",
	},
	fly = true , 
	fly_in = "air",
	walk_velocity = 2,
	run_velocity = 4,
	jump_height = 3,
	stepheight = 2,
	floats = 0,
	view_range = 16, --smartphone player not see long distance.
	drops = {
		{name = "mobs:chicken_feather", chance = 3, min = 0, max = 1},
	},
	water_damage = 1,
	lava_damage = 2,
	light_damage = 0,
	animation = {
		speed_normal = 30,
		stand_start = 0,
		stand_end = 40,
		fly_start = 50,			
		fly_end = 119,
		walk_start = 50,
		walk_end = 119,
		run_start = 50,
		run_end = 119,
		--punch_start = 0,
		--punch_end = 0,
	},
	
	follow = {
		"farming:seed_wheat", 
		"farming:seed_cotton", 
	},
	on_rightclick = function(self, clicker)

		if mobs:feed_tame(self, clicker, 4, true, true) then return end
		if mobs:protect(self, clicker) then return end
		if mobs:capture_mob(self, clicker, 50, 50, 90, false, nil) then return end

		-- by right-clicking owner can switch between staying and walking
		if self.owner and self.owner == clicker:get_player_name() then
			minetest.sound_play("birdie", {pos=self.object:get_pos(), gain=1.0, max_hear_distance = 5})
			if self.order ~= "stand" then
				self.order = "stand"
				self.state = "stand"
				self.object:set_velocity({x = 0, y = 0, z = 0})
				mobs:set_animation(self, "stand")
			else
				self.order = ""
				mobs:set_animation(self, "fly")
			end
		end
	end,
})
mobs:spawn({
	name = "birdie:birdie",
	nodes = {
		--"air",
		"default:leaves",
		"default:jungleleaves",
	},
	min_light = 10, 
	chance = 8000,
	min_height = 0,
	max_height = 200,
	day_toggle = true,
})

mobs:register_egg("birdie:birdie", "Birdie", "birdieegg.png", 1)


